package com.controller;

import com.entity.Phone;
import com.packdate.Packdate;
import com.resp.BaseResponseEntity;
import com.service.IPhoneService;
import com.service.impl.PhoneServiceimpl;
import com.utlils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 展示手机数据
 */
@WebServlet("/findAllPone")
public class FindAllPone extends HttpServlet {
    IPhoneService service=new PhoneServiceimpl();


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        BaseResponseEntity entity=null;
        List<Phone> all = service.findAll();
        if(all!=null){
             entity =new BaseResponseEntity(200,"查询成功",all);
        }else {
             entity = BaseResponseEntity.findPhonError();
        }
        ResponseUtils.responseToJson(resp,entity);


    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       doPost(req, resp);
    }

}
